//
//  XMView.m
//  Second
//
//  Created by Alex on 16/7/15.
//  Copyright © 2016年 蓝鸥科技有限公司西安分公司. All rights reserved.
//

#import "XMView.h"

@interface XMView ()

@property (nonatomic,strong)XMButton *menu1;
@property (nonatomic,strong)XMButton *menu2;
@property (nonatomic,strong)XMButton *menu3;


@end
static XMView *instanceMenuView;
@implementation XMView

- (instancetype)init{
    if (self = [super init]) {
        self.alpha = 0.1f;
    }
    return self;
}


- (void)showItems{
    CGPoint center = CGPointMake(kWidth / 2 - 20 , kHeight - 20);
    self.centerPoint = center;

    CGPoint point1 = CGPointMake(kWidth/2+50,kHeight - 100);
    CGPoint point2 = CGPointMake(kWidth/2-50,kHeight - 100);

    XMButton *menu1 = [XMButton buttonWithTitle:@"" imageTitle:@"camera" center:center color:nil];
  
    menu1.tag = 1;
    [menu1 addTarget:self action:@selector(_addExamApprovel:) forControlEvents:UIControlEventTouchUpInside];

    XMButton *menu2 = [XMButton buttonWithTitle:@"" imageTitle:@"photo" center:center color:nil];
    menu2.tag = 2;
    [menu2 addTarget:self action:@selector(_addExamApprovel:) forControlEvents:UIControlEventTouchUpInside];
    
    _menu1 = menu1;
    _menu2 = menu2;

    _menu1.alpha = 0;
    _menu2.alpha = 0;
  
    [kWindow addSubview:menu1];
    [kWindow addSubview:menu2];
  
    [UIView animateWithDuration:0.2 animations:^{
        _menu1.alpha = 1;
        _menu2.alpha = 1;

        _menu1.center = point1;
        _menu2.center = point2;

    }];
}

- (void)dismiss{
    
    [UIView animateWithDuration:0.2 animations:^{
        
        _menu1.center = self.centerPoint;
        _menu2.center = self.centerPoint;

        _menu1.alpha = 0;
        _menu2.alpha = 0;

    } completion:^(BOOL finished) {
        
        [_menu1 removeFromSuperview];
        [_menu2 removeFromSuperview];
  
    }];
}

- (void)dismissAtNow{
    
    [_menu1 removeFromSuperview];
    [_menu2 removeFromSuperview];

}

- (void)_addExamApprovel:(UIButton *)sender{

    if (self.clickAddButton) {
        
        self.clickAddButton(sender.tag, [sender valueForKey:@"backgroundColor"] );
}

    if (sender.tag == 1) {
        
        
    } else {
     
        
        
    }
    
    
    
}

+ (instancetype)standardMenuView{
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        instanceMenuView = [[self alloc] init];
    });
    return instanceMenuView;
}

@end
